博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【java小程序实战】小程序注销功能实现
阅读量:4183 次
发布时间:2019-05-26

本文共 2528 字,大约阅读时间需要 8 分钟。

小程序实战中,如何实现程序的注销功能呢?后端代码只要删除用户的redi缓存即可。小程序端在成功返回消息后,进行登陆页面的跳转。

文章目录

页面展示

在这里插入图片描述

小程序的mine.wxml代码

mine.wxss代码

page {  font-size: 14px;}.container {   background-color: whitesmoke;   display: flex;   flex-direction: column;   align-items: center;}.container-row {   display: flex;   flex-direction: row;   margin-bottom: 10px;   margin-top: 10px;}.info-items {   margin-left: 30px;}.face {   width: 180rpx;   height: 180rpx;   border-radius: 50%;   margin-top: 20px;}.nickname {   margin-top: 5px;   font-weight: bold;   font-size: 18px;}.logout {  margin-top: 3px;  float: right;}.follow {   margin-top: 3px;}.line {   width: 100%;   height: 1px;   background-color: gainsboro;   margin-top: 1px;}.container-video {   display: flex;   flex-direction: row;   margin-top: 20px;   text-align: center;   border: solid 1px;   line-height: 30px;}.video-info {   width: 100%;}.video-info-selected {   background-color: gainsboro;}.container-video-list {   display: flex;   flex-direction: row;   flex-wrap: wrap;}.videoImage {   width: 250rpx;   height: 180px;}

注销事件的代码mine.js

通过事件函数发起请求,后端处理成功返回结果,并跳转至登陆页面。

设置小程序的全局变量userInfo为null

//注销事件    logout: function () {      console.log("logout")      var user = app.userInfo;      var serverUrl = app.serverUrl;      wx.showLoading({        title: '请等待',      });      wx.request({        url: serverUrl+'/logout?userId=' + user.id,        method:"POST",        header: {          'content-type': 'application/json' //默认值        },        success: function (res) {           wx.hideLoading();           if( res.data.status == 200){             wx.showToast({               title: '注销成功',               icon: 'success',               duration: 20000             });             //注销成功,设置全局信息为null             app.userInfo = null;             wx.navigateTo({               url: '../login/login',             })           }        }      })    },

RegistLoginController 中注销代码

根据用户id,清楚redis中的缓存记录。

@ApiOperation(value="用户注销" , notes = "用户注销的接口")    @ApiImplicitParam(name = "userId", value = "用户id" ,required = true,                      dataType = "String", paramType = "query")    @PostMapping("/logout")    public IMoocJSONResult logout(String userId) {        System.out.println("userId:"+userId);          redis.del(USER_REDIS_SESSION + ":" + userId);           return IMoocJSONResult.ok();    }

转载地址:http://ijfoi.baihongyu.com/

你可能感兴趣的文章
菜鸟、夫子、玫林凯与测试
查看>>
无锁编程与分布式编程那个更适合多核CPU?
查看>>
多核系统中三种典型锁竞争的加速比分析
查看>>
多核新观念-象使用内存一样使用CPU?
查看>>
OpenMP创建线程中的锁及原子操作性能比较
查看>>
多核编程中的任务随机竞争模式的概率分析
查看>>
多核编程中的任务分组竞争模式
查看>>
模块分解原理与三权分立
查看>>
模块分解原理的探索
查看>>
90%程序员写不出无BUG的二分查找程序?
查看>>
C/C++代码检视要点
查看>>
Symbian中所体现的软件编程艺术
查看>>
c/c++中指针参数如何传递内存
查看>>
Symbian程序图标问题
查看>>
虚基类释义
查看>>
虚函数释义
查看>>
自动记录上次登陆成功的用户信息
查看>>
基于回合制的在线棋类对战游戏(图)
查看>>
一个开源的IoC采集服务器体系结构设计
查看>>
“人民币找零”问题的贪婪法解决算法
查看>>